<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Ads/classes/PhpFox_ServiceAds.class.php, $Author:  $ */



/** Implements some functionality for ads module
 * @package module.ads
 * @version $Id: PhpFox_ServiceAds.class.php 143 2008-01-07 05:17:38Z phpfoxsv $
 *
 */
class PhpFox_Mod_Ads_ServiceAds extends BaseService
{
    function getRandomAds($iType)
    {
    	$oCache = &App::newObject("Cache");
		$oCache->setFile("ads_". $iType.".php");

   		if ( !$oCache->isCached() )
    	{
    		$data = "";
    		$cacheData = $this->oDatabase->getRows("SELECT text FROM ". $this->oDatabase->getT('ads') ." WHERE type = '". $iType ."'");
    		foreach($cacheData as $items)
    		{
    			$data .= '\''. str_replace("'","\'",$items['text']) .'\','."\n";
    		}
			$oCache->save($data);
    	}

		$aAds = $oCache->doRequire();

		$iTotal = count($aAds);
		$iRand = (rand(1,$iTotal)-1);

		$ad['text'] = (isset($aAds[$iRand]) ? $aAds[$iRand] . ($iType == 3 ? '<br /><br />' : '') : '');

		return $ad;
    }
    
	function deleteCached($iType)
	{
		$oCache = &App::newObject("Cache");
		$oCache->rmFile("ads_". $iType.".php");
	}
}
?>